package xujiwen.transport.servlet;

import xujiwen.transport.bean.Owner;
import xujiwen.transport.Mgr.OwnerMgr;
import java.text.SimpleDateFormat;
import java.util.Date;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class for Servlet: Register
 * 
 */
public class ModifOwner extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ModifOwner() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doGet(final HttpServletRequest request,
			final HttpServletResponse response) throws ServletException,
			IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doPost(final HttpServletRequest request,
			final HttpServletResponse response) throws ServletException,
			IOException {
		/*final HttpSession session = request.getSession();
		final User user = (User)session.getAttribute("user");
		if (user==null){
			response.sendRedirect("login.jsp");
			System.out.println("未登陆");
			return ;
		}*/
		OwnerMgr om = new OwnerMgr();
		// 指明编码
		request.setCharacterEncoding("utf-8"); 
		
		//System.out.println(password + "\t" + email + "\t");
		try {
			final String oid = request.getParameter("oid");
			final String name = request.getParameter("oname");
			
			final String sex = request.getParameter("sex");
			final String phone = request.getParameter("phone");
			
			//MD5 md5 = new MD5();
			//final User upUser = new User();
			
			Owner owner = new Owner();
			
			owner.setName(name);
			owner.setOwnerId(oid);
			owner.setSex(sex);
			owner.setPhone(phone);
			
			om.Update(owner);
			
			System.out.println("车主信息修改成功");
		} catch(final NumberFormatException nfex){
			//response.sendRedirect("err.jsp");
			System.out.println("提交错误");			
			return ;
		}
		response.sendRedirect("operate/ownerMgr.jsp?searchStr=");
	}
}